package com.test.langchain4j.controller;

import com.test.langchain4j.service.ChatAssistant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 8/15/25 12:59 PM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
@Slf4j
public class OllamaChatController {
  @Autowired private ChatAssistant chatAssistant;

  @GetMapping("/ollama/chat")
  public String chat(@RequestParam(value = "question") String question) {
    String result = chatAssistant.chat(question);
    log.info("ollama问答结果: {}", result);
    return result;
  }

  @GetMapping(value = "/ollama/sse")
  public Flux<String> chatSse(@RequestParam(value = "prompt") String prompt) {
    log.info("---come in sse--- \n ollama sse问答结果: {}", prompt);
    return chatAssistant.chatFlux(prompt);
  }
}
